﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Forms;

namespace Wicresoft.Shell.Package.AppExp
{
    public class AdapterPropertyItemObject : BasePropertyItemObject 
    {
        private string imobiletype;

        public AdapterPropertyItemObject(TreeNode tn)
        {
            _tn = tn;
            imobiletype = _tn.Text;
        }

        protected override void SetProperties()
        {
            base.SetProperties();
            if (_tn != null)
            {
                if (_tn.Tag != null)
                {
                    string t_tag = _tn.Tag.ToString();
                    if (t_tag.StartsWith("FPIDM"))
                    {
                        string t_str = t_tag.Substring(5);
                        string[] ids = t_str.Split(';');
                        try
                        {
                            Workspace.GetDatabaseLogic().UpdateAdapterType(Convert.ToInt16(ids[1]), imobiletype);
                            _tn.Text = imobiletype;
                        }
                        catch
                        {
                            MessageBox.Show("Operation Failed!");
                        }
                    }
                }
            }
        }

        
        [Category("General")]
        [Description("Mobile Type property")]
        public string MobileType
        {
            get 
            {
                return imobiletype;
            }
            set 
            {
                imobiletype = value;
                SetProperties();
            }
        }
    }
}
